//
//  CompanyMainViewController.m
//  MyProject
//
//  Created by 石小强 on 2018/3/22.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "CompanyMainViewController.h"
#import "AnswersTableViewCell.h"
#import "CanHelpPeopleCollectionViewCell.h"
#import "CoworkerAskVC.h"
#import "MoreWorkmateVC.h"
#import "MoreWorkmateDecryptVC.h"
#import "CompanyVC.h"
#import "CompanyWorkmateLastCell.h"
#import "ReportOrCancelViewController.h"
#import "StringAndIndexModel.h"
#import "CompanyReviewViewController.h"
#import "EntryProtectDetailVC.h"
#import "WorkmateMainVC.h"
#import "CompanyCommentModel.h"
#import "MoreCompanyCommentViewController.h"
#import "CertificationViewController.h"
#import "CompanyInfoCertificateVC.h"
#import "UITableView+Empty.h"

@interface CompanyMainViewController ()

@property (nonatomic, strong) UIButton *collectB;
@property (nonatomic, strong) NSMutableArray *commentArray;
@property (nonatomic, strong) NSMutableArray *workmateArray;
@property (nonatomic, strong) NSMutableArray *decrypArray;
@property (nonatomic, strong) NSMutableArray *questionArray;

@end

@implementation CompanyMainViewController {
    NSInteger _pageNo;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupNav];
    
    [self setupView];
    
    /** 获取企业基本信息 */
//    [self loadCompanyData];
//    [self loadWorkmateData];
//    [self loadDecryptData];
//    [self loadQuestionData];
    
    [self getUserCollected];
    [self.tableView.mj_header beginRefreshing];
}

- (void)setupNav {
    self.navigationItem.title = @"公司主页";
    UIButton *tipB = [[UIButton alloc] init];
    [tipB setImage:[UIImage imageNamed:@"ic_tip_black"] forState:UIControlStateNormal];
    [tipB setMj_size:tipB.currentImage.size];
    [tipB addTarget:self action:@selector(tipBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *shareB = [[UIButton alloc] init];
    [shareB setImage:[UIImage imageNamed:@"ic_share_black"] forState:UIControlStateNormal];
    [shareB setMj_size:shareB.currentImage.size];
    [shareB addTarget:self action:@selector(shareBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *collectB = [[UIButton alloc] init];
    [collectB setImage:[UIImage imageNamed:@"ic_collect_unselect_black"] forState:UIControlStateNormal];
    [collectB setImage:[UIImage imageNamed:@"ic_collect_select_black"] forState:UIControlStateSelected];
    [collectB setMj_size:collectB.currentImage.size];
    [collectB addTarget:self action:@selector(collectBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.collectB = collectB;
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:shareB];
    self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc] initWithCustomView:tipB], [[UIBarButtonItem alloc] initWithCustomView:nil], [[UIBarButtonItem alloc] initWithCustomView:shareB], [[UIBarButtonItem alloc] initWithCustomView:nil], [[UIBarButtonItem alloc] initWithCustomView:collectB]];
}

- (void)tipBtnClick {
    NSLog(@"tipBtnClick");
    NSArray *msgs = @[@"信息内容不真实", @"泄露/索取个人隐私", @"封建迷信、反动思想、涉黄涉暴等政治敏感内容", @"发布广告/虚假信息/传销等信息", @"辱骂/诽谤/恶意骚扰等人身攻击", @"其他"];
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < msgs.count; i++) {
        StringAndIndexModel *model = [[StringAndIndexModel alloc] init];
        if (i == 0) {
            model.index = 1;
        } else {
            model.index = 0;
        }
        model.msg = msgs[i];
        [dataArray addObject:model];
    }
    
    ReportOrCancelViewController *vc = [[ReportOrCancelViewController alloc] init];
    vc.index = 1;
    vc.dataArray = dataArray;
    vc.relatedId = self.companyId;
    vc.relatedType = @"REPORT_TYPE_COMPANY";
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 分享按钮点击事件
- (void)shareBtnClick {
    NSLog(@"shareBtnClick");
    [self showShareView];
}

#pragma mark - 收藏按钮点击事件
- (void)collectBtnClick {
    NSLog(@"collectBtnClick");
    if (self.collectB.selected) {
        // 取消收藏
        WS(weakSelf)
        [self showProgressWithView:self.view animated:YES];
        [SendRequest cancelCollectWithRelatedId:self.companyId result:^(NSDictionary *result, NSError *error) {
            [weakSelf hideProgress:self.view animated:YES];
            result = [CommonUtils decryptDicWithResult:result];
            if([result[@"result"] integerValue] == 1) {
                /**取消收藏成功*/
                self.collectB.selected = !self.collectB.selected;
            } else {
                [CommonUtils showToast:[result objectForKey:@"msg"]];
            }
        }];
    } else {
        // 收藏
        WS(weakSelf)
        [self showProgressWithView:self.view animated:YES];
        [SendRequest collectWithRelatedId:self.companyId andType:@"COLLECTION_TYPE_COMPANY" result:^(NSDictionary *result, NSError *error) {
            [weakSelf hideProgress:self.view animated:YES];
            result = [CommonUtils decryptDicWithResult:result];
            if([result[@"result"] integerValue] == 1) {
                /**收藏成功*/
                self.collectB.selected = !self.collectB.selected;
            } else {
                [CommonUtils showToast:[result objectForKey:@"msg"]];
            }
        }];
    }
    
    self.collectB.selected = !self.collectB.selected;
}

#pragma mark - 公司点评按钮点击事件
/** 公司点评按钮点击事件 */
- (IBAction)companyReviewBtnClick:(id)sender {
    CompanyReviewViewController *vc = [[CompanyReviewViewController alloc] init];
    vc.companyId = self.companyModel.companyId;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:nav animated:NO completion:nil];
}

- (void)setupView {
    self.tableView.backgroundColor = kStyleColor;
    // tableView
//    self.tableViewHeaderView.frame = CGRectMake(0, 0, kScreenWidth, 805);
    self.tableViewHeaderView.frame = CGRectMake(0, 0, kScreenWidth, 775);
    self.tableView.tableHeaderView = self.tableViewHeaderView;
    [self.tableView registerNib:[UINib nibWithNibName:@"AnswersTableViewCell" bundle:nil] forCellReuseIdentifier:@"CompanyMainAnswersCell"];
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.estimatedRowHeight = 184.0f;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
    }
    
    self.commentHeaderIV.layer.cornerRadius = 14.5;
    self.commentHeaderIV.layer.masksToBounds = YES;
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        _pageNo = 1;
        [self loadCompanyData];
        [self getCommentListByCompanyId];
        [self loadWorkmateData];
        [self loadDecryptData];
        [self loadQuestionData];
    }];
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        _pageNo += 1;
        [self loadQuestionData];
    }];
    
    // collectionView
    [self.coworkerCollectionView registerNib:[UINib nibWithNibName:@"CompanyMainWorkmateCell" bundle:nil]  forCellWithReuseIdentifier:@"CompanyMainWorkmateCell"];
    [self.coworkerCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([CompanyWorkmateLastCell class]) bundle:nil] forCellWithReuseIdentifier:@"CompanyWorkmateLastCell"];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.minimumInteritemSpacing = 15;
    flowLayout.minimumLineSpacing = 15;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.sectionInset = UIEdgeInsetsZero;
    flowLayout.itemSize = CGSizeMake(120,158);
    flowLayout.sectionInset = UIEdgeInsetsMake(0,15, 0, 15);
    self.coworkerCollectionView.collectionViewLayout = flowLayout;
}

#pragma mark - 根据企业ID查询企业信息

- (void)loadCompanyData {
    WS(weakSelf)
    [SendRequest getCompanyInfoByCompanyId:self.companyId result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        if([result[@"result"] integerValue] == 1) {
            SaintiLog(@"根据企业ID查询企业信息 = %@", [result objectForKey:@"data"]);
            weakSelf.companyModel = [CompanyModel mj_objectWithKeyValues:[result objectForKey:@"data"]];
            [weakSelf resetMainView];
        } else {
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}

- (void)resetMainView {
    [self.companyIcon sd_setImageWithURL:ImageURLWithKey(self.companyModel.companyLogo) placeholderImage:PlaceholderImageCompany];
    self.companyNameL.text = self.companyModel.companyName;
    self.companyDescL.text = [NSString stringWithFormat:@"%@/%@/%@", self.companyModel.industryName, self.companyModel.financingScaleName, self.companyModel.personnelScaleName];
    self.companyAreaL.text = self.companyModel.companyAddress;
    self.companyRankL.text = [NSString stringWithFormat:@"%@分", self.companyModel.avgScore];
    
    self.zongheScoreL.text = self.companyModel.avgScore;
    
    CGFloat score = [self.companyModel.recommendScore floatValue] * 100;
    self.recommendScoreL.text = [NSString stringWithFormat:@"%.0f%%", score];
}

#pragma mark - 查询公司点评
/** 查询公司点评 */
- (void)getCommentListByCompanyId {
    WS(weakSelf)
    [SendRequest getCompanyIncumbentCommentsByCompanyId:self.companyId andPageNo:@"1" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        if([result[@"result"] integerValue] == 1) {
            SaintiLog(@"查询公司点评列表 = %@", [[result objectForKey:@"data"] objectForKey:@"list"]);
            
            NSArray *datas = [CompanyCommentModel mj_objectArrayWithKeyValuesArray:[[result objectForKey:@"data"] objectForKey:@"list"]];
            [weakSelf.commentArray removeAllObjects];
            [weakSelf.commentArray addObjectsFromArray:datas];
            
//            if (weakSelf.commentArray.count > 0) {
//                [weakSelf resetCommentView];
//            }
            [weakSelf resetCommentView];
        } else {
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}

- (void)resetCommentView {
    if (self.commentArray.count == 0) {
        self.yuangongDianpingView.hidden = YES;
        self.yuangongdianpingHeight.constant = 0;
    } else if (self.commentArray.count == 1) {
        self.yuangongDianpingView.hidden = NO;
        CompanyCommentModel *companyCommentM = [self.commentArray objectAtIndex:0];
        [self.commentHeaderIV sd_setImageWithURL:ImageURLWithKey(companyCommentM.headImg) placeholderImage:PlaceholderImagePeople];
        self.commentNamePositionYearL.text = [NSString stringWithFormat:@"%@ | %@ | 已在职%@年", companyCommentM.nickName, companyCommentM.positionName, companyCommentM.inServiceTime];
        self.commentContentL.text = companyCommentM.content;
//        [self.commentNumBtn setTitle:[NSString stringWithFormat:@"查看全部点评（%zd）", self.commentArray.count] forState:UIControlStateNormal];
        self.commentNumBtn.hidden = YES;
        if (companyCommentM.content && companyCommentM.content.length > 0) {
            self.yuangongdianpingHeight.constant = 198 - 53 + self.commentContentL.mj_h - 40;
        } else {
            self.yuangongdianpingHeight.constant = 198 - 53 - 15 - 40;
        }
    }
    else {
        self.yuangongDianpingView.hidden = NO;
        CompanyCommentModel *companyCommentM = [self.commentArray objectAtIndex:0];
        [self.commentHeaderIV sd_setImageWithURL:ImageURLWithKey(companyCommentM.headImg) placeholderImage:PlaceholderImagePeople];
        self.commentNamePositionYearL.text = [NSString stringWithFormat:@"%@ | %@ | 已在职%@年", companyCommentM.nickName, companyCommentM.positionName, companyCommentM.inServiceTime];
        self.commentNumBtn.hidden = NO;
        self.commentContentL.text = companyCommentM.content;
        [self.commentNumBtn setTitle:[NSString stringWithFormat:@"查看全部点评（%zd）", self.commentArray.count] forState:UIControlStateNormal];
        
        if (companyCommentM.content && companyCommentM.content.length > 0) {
            self.yuangongdianpingHeight.constant = 198 - 53 + self.commentContentL.mj_h;
        } else {
            self.yuangongdianpingHeight.constant = 198 - 53 - 15;
        }
    }
    
    [self resetTableViewHeaderHeight];
}

- (IBAction)commentNumBtnClick:(id)sender {
    MoreCompanyCommentViewController *vc = [[MoreCompanyCommentViewController alloc] init];
    vc.companyId = self.companyId;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 获取在职同事数据
// 获取在职同事数据
- (void)loadWorkmateData {
    WS(weakSelf)
    [SendRequest getCompanyIncumbentListByCompanyId:self.companyId andPageNo:@"1" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        if([result[@"result"] integerValue] == 1) {
            SaintiLog(@"获取在职同事数据 = %@", [result objectForKey:@"data"]);
            NSArray *datas = [WorkmateModel mj_objectArrayWithKeyValuesArray:[[result objectForKey:@"data"] objectForKey:@"list"]];
            [weakSelf.workmateArray removeAllObjects];
            [weakSelf.workmateArray addObjectsFromArray:datas];
            
            WorkmateModel *model = [[WorkmateModel alloc] init];
            [weakSelf.workmateArray addObject:model];
            [weakSelf resetWorkmateView];
            
            [weakSelf.coworkerCollectionView reloadData];
        } else {
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}

- (void)resetWorkmateView {
    if (self.workmateArray.count > 1) {
        self.coworkerCollectionViewTitleViewHeight.constant = 31;
        self.coworkerCollectionViewHeight.constant = 148;
        
        self.coworkTitleViewIconIV.hidden = NO;
        self.coworkTitleViewTitleL.hidden = NO;
    } else {
        self.coworkerCollectionViewTitleViewHeight.constant = 0;
        self.coworkerCollectionViewHeight.constant = 0;
        
        self.coworkTitleViewIconIV.hidden = YES;
        self.coworkTitleViewTitleL.hidden = YES;
    }
    [self resetTableViewHeaderHeight];
}

#pragma mark - 获取同事解密数据
// 获取同事解密数据
- (void)loadDecryptData {
    WS(weakSelf)
    [SendRequest getIncumbentDecryptByCompanyId:self.companyId andPageNo:@"1" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        if([result[@"result"] integerValue] == 1) {
            SaintiLog(@"获取同事解密数据 = %@", [result objectForKey:@"data"]);
            NSArray *datas = [DecryptModel mj_objectArrayWithKeyValuesArray:[[result objectForKey:@"data"] objectForKey:@"list"]];
            [weakSelf.decrypArray removeAllObjects];
            [weakSelf.decrypArray addObjectsFromArray:datas];
            [weakSelf resetDecryptViewExt];
        } else {
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}

- (void)resetDecryptViewExt {
    for (UIView *con in self.decryptView.subviews) {
        [con removeFromSuperview];
    }
    
    // 上下间距是10，一条数据的高度是22
    CGFloat decryptH = 86;
    if (self.decrypArray.count == 0) {
        decryptH = 0;
    } else if (self.decrypArray.count >= 3) {
        decryptH = 86;
    } else {
        decryptH = 20 + 22 * self.decrypArray.count;
    }
    
    self.decryptViewHeight.constant = decryptH;
    if (self.decrypArray.count == 0) {
        self.decryptViewTitleViewHeight.constant = 0;
        
        self.decryptTitleViewIconIV.hidden = YES;
        self.decryptTitleViewTitleL.hidden = YES;
        self.decryptTitleViewMoreB.hidden = YES;
        self.decryptTitleViewMoreBtnIV.hidden = YES;
        self.decryptTitleViewMoreBtnTitleL.hidden = YES;
    } else {
        self.decryptViewTitleViewHeight.constant = 42;
        
        self.decryptTitleViewIconIV.hidden = NO;
        self.decryptTitleViewTitleL.hidden = NO;
        self.decryptTitleViewMoreB.hidden = NO;
        self.decryptTitleViewMoreBtnIV.hidden = NO;
        self.decryptTitleViewMoreBtnTitleL.hidden = NO;
    }
    [self resetTableViewHeaderHeight];
    
    UIView *indicatorV = [[UIView alloc] initWithFrame:CGRectMake(0, decryptH * 0.25, 4, decryptH * 0.5)];
    indicatorV.backgroundColor = UIColorFromRGB(0x00BCCC);
    [self.decryptView addSubview:indicatorV];
    
    for (NSInteger i = 0; i < self.decrypArray.count; i++) {
        if (i > 2) {  // 最多显示三个
            break;
        }
        
        DecryptModel *model = [self.decrypArray objectAtIndex:i];
        
        UIView *leftV = [[UIView alloc] initWithFrame:CGRectMake(19, 10 + 9.5 + 22 * i, 3, 3)];
        leftV.backgroundColor = indicatorV.backgroundColor;
        [self.decryptView addSubview:leftV];
        
        UILabel *titleL = [[UILabel alloc] initWithFrame:CGRectMake(27, 10 + 22 * i, kScreenWidth - 120, 22)];
        titleL.text = model.title;
        titleL.font = [UIFont fontWithName:@"PingFang SC" size:14];
        titleL.textColor = UIColorFromRGB(0x383F42);
        [self.decryptView addSubview:titleL];
        
        UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(titleL.frame) + 18, 10 + 22 * i + 4.5, 13, 13)];
        iv.image = [UIImage imageNamed:@"ic_lock"];
        [self.decryptView addSubview:iv];
        
        UILabel *numL = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(iv.frame) + 7, 10 + 22 * i, 63 - 38, 22)];
        numL.text = model.quantityPurchased;
        numL.textColor = UIColorFromRGB(0x96ABB5);
        numL.font = [UIFont fontWithName:@"PingFangSC-Regular" size:11];
        [self.decryptView addSubview:numL];
        
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 10 + 22 * i, kScreenWidth - 30, 22)];
        btn.tag = i;
        [btn addTarget:self action:@selector(decryptsBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.decryptView addSubview:btn];
    }
}

- (void)decryptsBtnClick:(UIButton *)btn {
    EntryProtectDetailVC *vc = [[EntryProtectDetailVC alloc] init];
    vc.index = 1;
    DecryptModel *decrypt = [self.decrypArray objectAtIndex:btn.tag];
    vc.decryptId = decrypt.incumbentDecryptId;
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)resetDecryptView {
    if (self.decrypArray.count == 0) {
        self.decryptOneL.hidden = YES;
        self.decryptOneNumL.hidden = YES;
        self.decryptTwoL.hidden = YES;
        self.decryptTwoNumL.hidden = YES;
        self.decryptThreeL.hidden = YES;
        self.decryptThreeNumL.hidden = YES;
        self.decryptOneB.hidden = YES;
        self.decryptTwoB.hidden = YES;
        self.decryptThreeB.hidden = YES;
    } else if (self.decrypArray.count == 1) {
        self.decryptOneL.hidden = NO;
        self.decryptOneNumL.hidden = NO;
        self.decryptOneB.hidden = NO;
        
        DecryptModel *one = [self.decrypArray objectAtIndex:0];
        self.decryptOneL.text = one.title;
        self.decryptOneNumL.text = one.evaluateCount;
        
        self.decryptTwoL.hidden = YES;
        self.decryptTwoNumL.hidden = YES;
        self.decryptThreeL.hidden = YES;
        self.decryptThreeNumL.hidden = YES;
        self.decryptTwoB.hidden = YES;
        self.decryptThreeB.hidden = YES;
    } else if (self.decrypArray.count == 2) {
        self.decryptOneL.hidden = NO;
        self.decryptOneNumL.hidden = NO;
        self.decryptOneB.hidden = NO;
        
        DecryptModel *one = [self.decrypArray objectAtIndex:0];
        self.decryptOneL.text = one.title;
        self.decryptOneNumL.text = one.evaluateCount;
        
        self.decryptTwoL.hidden = NO;
        self.decryptTwoNumL.hidden = NO;
        self.decryptTwoB.hidden = NO;
        
        DecryptModel *two = [self.decrypArray objectAtIndex:1];
        self.decryptTwoL.text = two.title;
        self.decryptTwoNumL.text = two.evaluateCount;
        
        self.decryptThreeL.hidden = YES;
        self.decryptThreeNumL.hidden = YES;
        self.decryptThreeB.hidden = YES;
    } else {
        self.decryptOneL.hidden = NO;
        self.decryptOneNumL.hidden = NO;
        self.decryptOneB.hidden = NO;
        
        DecryptModel *one = [self.decrypArray objectAtIndex:0];
        self.decryptOneL.text = one.title;
        self.decryptOneNumL.text = one.evaluateCount;
        
        self.decryptTwoL.hidden = NO;
        self.decryptTwoNumL.hidden = NO;
        self.decryptTwoB.hidden = NO;
        
        DecryptModel *two = [self.decrypArray objectAtIndex:1];
        self.decryptTwoL.text = two.title;
        self.decryptTwoNumL.text = two.evaluateCount;
        
        self.decryptThreeL.hidden = NO;
        self.decryptThreeNumL.hidden = NO;
        self.decryptThreeB.hidden = NO;
        
        DecryptModel *three = [self.decrypArray objectAtIndex:2];
        self.decryptThreeL.text = three.title;
        self.decryptThreeNumL.text = three.evaluateCount;
    }
}

#pragma mark - 解密数据点击事件--跳转解密详情

- (IBAction)decryptBtnClick:(id)sender {
    EntryProtectDetailVC *vc = [[EntryProtectDetailVC alloc] init];
    vc.index = 1;
    DecryptModel *decrypt = [self.decrypArray objectAtIndex:0];
    if (sender == self.decryptOneB) {
        decrypt = [self.decrypArray objectAtIndex:0];
    } else if (sender == self.decryptTwoB) {
        decrypt = [self.decrypArray objectAtIndex:1];
    } else {
        decrypt = [self.decrypArray objectAtIndex:2];
    }
    vc.decryptId = decrypt.incumbentDecryptId;
    [self.navigationController pushViewController:vc animated:YES];
}

// 获取同事问答数据
- (void)loadQuestionData {
    WS(weakSelf)
    [SendRequest getQuestiosOfCompanyByCompanyId:self.companyId andPageNo:[NSString stringWithFormat:@"%zd", _pageNo] result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        if([result[@"result"] integerValue] == 1) {
            SaintiLog(@"获取同事问答数据 = %@", [result objectForKey:@"data"]);
            NSArray *datas = [QuestionModel mj_objectArrayWithKeyValuesArray:[[result objectForKey:@"data"] objectForKey:@"list"]];
            
            if (_pageNo == 1) {
                [weakSelf.questionArray removeAllObjects];
                [weakSelf.questionArray addObjectsFromArray:datas];
                [weakSelf.tableView reloadData];
                [weakSelf.tableView.mj_header endRefreshing];
                [weakSelf.tableView.mj_footer endRefreshing];
            } else {
                [weakSelf.questionArray addObjectsFromArray:datas];
                [weakSelf.tableView reloadData];
                if (datas.count < kNumOfPageIntSize) {
                    [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
                } else {
                    [weakSelf.tableView.mj_footer endRefreshing];
                }
            }
        } else {
            [CommonUtils showToast:[result objectForKey:@"msg"]];
            if (_pageNo == 1) {
                [weakSelf.tableView.mj_header endRefreshing];
            } else {
                [weakSelf.tableView.mj_footer endRefreshing];
            }
        }
    }];
}

#pragma mark - UICollectionViewDelegate, UICollectionViewDelegate

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.workmateArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == self.workmateArray.count - 1) {
        CompanyWorkmateLastCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CompanyWorkmateLastCell" forIndexPath:indexPath];
        return cell;
    } else {
        CompanyMainWorkmateCell *cell  = [collectionView dequeueReusableCellWithReuseIdentifier:@"CompanyMainWorkmateCell" forIndexPath:indexPath];
        cell.contentView.backgroundColor = UIColorFromRGB(0xF2F5FA);
        cell.model = [self.workmateArray objectAtIndex:indexPath.row];
        return cell;
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == self.workmateArray.count - 1) {
        MoreWorkmateVC *vc = [[MoreWorkmateVC alloc] init];
        vc.companyId = self.companyId;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        WorkmateMainVC *wmVC = [[WorkmateMainVC alloc] init];
        WorkmateModel *model = [self.workmateArray objectAtIndex:indexPath.row];
        wmVC.userId = model.userId;
        [self.navigationController pushViewController:wmVC animated:YES];
    }
}

#pragma mark - UITableViewDelegate, UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.questionArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AnswersTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CompanyMainAnswersCell"];
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    cell.model = [self.questionArray objectAtIndex:indexPath.row];
    return cell;
}

- (IBAction)companyBtnClick:(id)sender {
    CompanyVC *vc = [[CompanyVC alloc] init];
    vc.companyModel = self.companyModel;
    vc.companyId = self.companyModel.companyId;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)jobBtnClick:(id)sender {
}

- (IBAction)moreDecryptBtnClick:(id)sender {
    MoreWorkmateDecryptVC *vc = [[MoreWorkmateDecryptVC alloc] init];
    vc.companyId = self.companyId;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)notAuthenticateAskBtnClick:(id)sender {
    CoworkerAskVC *vc = [[CoworkerAskVC alloc] init];
    vc.companyId = self.companyId;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)notAuthenticateApplyBtnClick:(id)sender {
//    CertificationViewController *vc = [[CertificationViewController alloc] init];
    CompanyInfoCertificateVC *vc = [[CompanyInfoCertificateVC alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:nav animated:YES completion:nil];
}

- (IBAction)authenticateAskBtnClick:(id)sender {
    CoworkerAskVC *vc = [[CoworkerAskVC alloc] init];
    vc.companyId = self.companyId;
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSMutableArray *)commentArray {
    if (!_commentArray) {
        _commentArray = [[NSMutableArray alloc] init];
    }
    return _commentArray;
}

- (NSMutableArray *)workmateArray {
    if (!_workmateArray) {
        _workmateArray = [[NSMutableArray alloc] init];
    }
    return _workmateArray;
}

- (NSMutableArray *)decrypArray {
    if (!_decrypArray) {
        _decrypArray = [[NSMutableArray alloc] init];
    }
    return _decrypArray;
}

- (NSMutableArray *)questionArray {
    if (!_questionArray) {
        _questionArray = [[NSMutableArray alloc] init];
    }
    return _questionArray;
}

#pragma mark - 重新设计高度

- (void)resetTableViewHeaderHeight {
    CGFloat tableViewHeaderViewHeight =  129 + 137 + self.yuangongdianpingHeight.constant + self.coworkerCollectionViewTitleViewHeight.constant + self.coworkerCollectionViewHeight.constant + self.decryptViewTitleViewHeight.constant + self.decryptViewHeight.constant + 30;
    self.tableViewHeaderView.frame = CGRectMake(0, 0, kScreenWidth, tableViewHeaderViewHeight);
    self.tableView.tableHeaderView = self.tableViewHeaderView;
    [self.tableView reloadData];
}

#pragma mark - 获取用户对公司的收藏信息，并判断本职位是否收藏

- (void)getUserCollected {
    WS(weakSelf)
    [SendRequest getUserCollectedWithType:@"COLLECTION_TYPE_COMPANY" result:^(NSDictionary *result, NSError *error) {
        [weakSelf hideProgress:self.view animated:YES];
        result = [CommonUtils decryptDicWithResult:result];
        if([result[@"result"] integerValue] == 1) {
            SaintiLog(@"用户对职位的收藏信息列表 = %@", [[result objectForKey:@"data"] objectForKey:@"list"]);
            
            NSArray *datas = [[result objectForKey:@"data"] objectForKey:@"list"];
            if (datas && datas.count > 0) {
                for (NSDictionary *dict in datas) {
                    NSString *companyId_dict = [[dict objectForKey:@"details"] objectForKey:@"companyId"];
                    if ([companyId_dict integerValue] == [self.companyId integerValue]) {
                        self.collectB.selected = YES;
                        break;
                    }
                }
            }
        } else {
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}

- (void)loadAuthenticationStatus {
    WS(weakSelf)
    [YJMSendRequest postDataWithParameters:@{} url:@"incumbent/getIncumbentStateOfAuthentication" result:^(NSDictionary *result, NSError *error) {
        result = [CommonUtils decryptDicWithResult:result];
        [self hideProgress:self.view animated:YES];
        if([result[@"result"] integerValue] == 1)
        {
            NSInteger isAuthentication = [result[@"data"][@"state"] integerValue];
            if (isAuthentication == 1) {
//                已认证
                weakSelf.notAuthenticateAskBtn.hidden = YES;
                weakSelf.notAuthenticateApplyBtn.hidden = YES;
                weakSelf.authenticateAskBtn.hidden = NO;
            } else {
//                未认证
                weakSelf.notAuthenticateAskBtn.hidden = NO;
                weakSelf.notAuthenticateApplyBtn.hidden = NO;
                weakSelf.authenticateAskBtn.hidden = YES;
            }
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = NO;
}

@end
